<template>
  <div class="app-container">
    <el-form
    :model="queryParams"
      ref="queryForm"
      size="small"
      v-show="showSearch"
      label-width="0px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="" prop="assetTagNumber">
            <el-input
              v-model="queryParams.assetTagNumber"
              placeholder="固定资产标签编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="sysCardNumber">
            <el-input
              v-model="queryParams.sysCardNumber"
              placeholder="固定资产管理系统卡片号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="deviceType">
            <el-select v-model="queryParams.deviceType" size="small" placeholder="设备类型" style="width:100%"
                       clearable
            >
              <el-option
                v-for="dict in dict.type.fa_device_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="deviceName">
            <el-input
              v-model="queryParams.deviceName"
              placeholder="设备名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="claimingDate">
            <el-date-picker
              size="small"
              v-model="claimingDateDateRange"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="领用开始日期"
              end-placeholder="领用结束日期"
           
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="originalOwner">
            <el-input
              v-model="queryParams.originalOwner"
              placeholder="原领用人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
      <!-- </el-row> -->
      <!-- <el-row :gutter="20"> -->
        <el-col :span="6">
          <el-form-item label="" prop="discRepletion">
            <el-input
              v-model="queryParams.discRepletion"
              placeholder="盘实"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="tag">
            <el-input
              v-model="queryParams.tag"
              placeholder="标签"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="status">
            <el-select v-model="queryParams.status" size="small" placeholder="设备状态" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="retirementLife">
            <el-input
              v-model="queryParams.retirementLife"
              placeholder="报废年限"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="disposalScheme">
            <el-select v-model="queryParams.disposalScheme" size="small" placeholder="处置方案" style="width:100%"
                       clearable
            >
              <el-option
                v-for="dict in dict.type.fa_disposal_scheme"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="department">
            <el-select v-model="queryParams.department" size="small" placeholder="所属部门" style="width:100%"
                       clearable
            >
              <el-option
                v-for="item in deptOptions"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptName">
              </el-option>
            </el-select>
            
          </el-form-item>
        </el-col>
        <el-col :span="6">

          <el-form-item label="" prop="disposalPriority">
            <el-select v-model="queryParams.disposalPriority" size="small" placeholder="处置优先级" style="width:100%"
                       clearable
            >
              <el-option
                v-for="dict in dict.type.fa_disposal_priority"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="retirementStatus">
            <el-select v-model="queryParams.retirementStatus" size="small" placeholder="报废状态" style="width:100%"
                       clearable
            >
              <el-option
                v-for="dict in dict.type.fa_retirement_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="retirementDate">
            <el-date-picker
              size="small"
              v-model="retirementDateDateRange"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="报废开始日期"
              end-placeholder="报废结束日期"
              
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-upload action="#" :auto-upload="false" :show-file-list="false"

            accept="application/msexcel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
            :on-change="upLoadExcel">
            <el-button
          type="success"
          plain
          icon="el-icon-download"
          size="mini"
        >导入
        </el-button>
        </el-upload>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleExport"
          :disabled='multiple'
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleQuery"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" @sort-change="changeTableSort" ref="multipleTable" :data="excutionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" fixed="left" align="center"/>
      <el-table-column label="固定资产标签编号" align="center" fixed="left" prop="assetTagNumber" width="150"></el-table-column>
      <el-table-column label="云中心资产标签" align="center" fixed="left" prop="cloudCenterAssetTag" width="120"
      ></el-table-column>
      <el-table-column label="固定资产增加通知单固定资产编号" align="center" prop="noticeAssetNumber" width="220"></el-table-column>
      <el-table-column label="固定资产增加通知单编号" align="center" prop="noticeNumber" width="180"></el-table-column>
      <el-table-column label="固定资产管理系统卡片号" align="center" prop="sysCardNumber" width="180"></el-table-column>
      <el-table-column label="固定资产管理系统卡片唯一编号" align="center" prop="sysCardUniqueNumber" width="220"></el-table-column>
      <el-table-column label="固定资产管理系统目录代码" align="center" prop="sysDirectoryCode" width="180"></el-table-column>
      <el-table-column label="设备类型" align="center" prop="deviceType" width="120">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_device_type, row.deviceType) }}</template>
      </el-table-column>
      <el-table-column label="资产分类" align="center" prop="assetClassify" width="150">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_asset_classify, row.assetClassify) }}</template>
      </el-table-column>
      <el-table-column label="分类" align="center" prop="classify" width="120">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_classify, row.classify) }}</template>
      </el-table-column>
      <el-table-column label="设备名称" align="center" prop="deviceName" width="120"></el-table-column>
      <el-table-column label="品牌" align="center" prop="brand" width="100"></el-table-column>
      
      <el-table-column label="设备型号" align="center" prop="deviceModel" width="120"></el-table-column>
      <el-table-column label="设备规格" align="center" prop="deviceSpec" width="120"></el-table-column>
      <el-table-column label="序列号" align="center" prop="serialNumber" width="120"></el-table-column>
      <el-table-column label="数量" align="center" prop="quantity" width="80"></el-table-column>
      <el-table-column label="单位" align="center" prop="unit" width="90"></el-table-column>
      <el-table-column label="金额" align="center" prop="amount" width="100"></el-table-column>
      <el-table-column label="重要程度" align="center" prop="importance" width="80"></el-table-column>
      <el-table-column label="固定资产明细账凭单号" align="center" prop="detailedAccountVoucherNumber" width="150"
      ></el-table-column>
      <el-table-column label="使用人" align="center" prop="peopleUse" width="90"></el-table-column>
      <el-table-column label="保管人" align="center" prop="preserver" width="90"></el-table-column>
      <el-table-column label="领用日期" sortable align="center" prop="claimingDate" width="150"></el-table-column>
      <el-table-column label="办公场所" align="center" prop="officeSpace" width="150"></el-table-column>
      <el-table-column label="存放区域" align="center" prop="storageArea" width="150"></el-table-column>
      <el-table-column label="详细位置" align="center" prop="detailedLocation" width="180"></el-table-column>
      <el-table-column label="来源" align="center" prop="source" width="100"></el-table-column>
      <el-table-column label="组织采购形式" align="center" prop="organizationalPurchasingForm" width="100">
        <template slot-scope="{row}">{{
            typeFormat(dict.type.fa_organizational_purchasing_form, row.organizationalPurchasingForm)
          }}
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center"  prop="remark" width="180"></el-table-column>
      <el-table-column label="原领用人" align="center" prop="originalOwner" width="100"></el-table-column>
      <el-table-column label="盘实" align="center" prop="discRepletion" width="100"></el-table-column>
      <el-table-column label="标签" align="center" prop="tag" width="100"></el-table-column>
      <el-table-column label="设备状态" align="center" prop="status" width="100">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_status, row.status) }}</template>
      </el-table-column>
      <el-table-column label="报废年限" align="center" prop="retirementLife" width="100"></el-table-column>
      <el-table-column label="处置方案" align="center" prop="disposalScheme" width="100">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_disposal_scheme, row.disposalScheme) }}</template>
      </el-table-column>
      <el-table-column label="所属部门" align="center" prop="department" width="100"></el-table-column>
      <el-table-column label="处置优先级" align="center" prop="disposalPriority" width="100">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_disposal_priority, row.disposalPriority) }}</template>
      </el-table-column>
      <el-table-column label="报废日期" sortable align="center" prop="retirementDate" width="150"></el-table-column>
      <el-table-column label="报废状态" align="center" prop="retirementStatus" width="100">
        <template slot-scope="{row}">{{ typeFormat(dict.type.fa_retirement_status, row.retirementStatus) }}</template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center"  prop="remark" width="180"></el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="230">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-top-right"
            @click="handleMove(scope.row)"
          >调拨
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-cpu"
            @click="handlInvalid(scope.row)"
          >报废
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="handleEdit(scope.row,0)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleEdit(scope.row,1)"
          >详细
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
          >查看详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handleQuery"
    />

    <Edit ref="assetsEdit" @refresh="handleQuery" :deptOptions="deptOptions"/>
    <MoveAndInvalid ref="MoveAndInvalid"></MoveAndInvalid>
    <!-- 固定资产管理导入 -->
    <!-- <div class="container">
      <el-dialog title="数据导入" :visible.sync="importVisible">
        <div>
          <el-steps :active="1">
            <el-step title="上传文件"></el-step>
            <el-step title="数据预览"></el-step>
            <el-step title="导入数据"></el-step>
            <el-step title="导入完成"></el-step>
          </el-steps>
        </div>
        <div>
          <el-card style="margin-top:20px">
            <div>
              <h3><strong>填写导入数据信息</strong></h3>
              <h5>请按照数据模板的格式准备导入数据，模板中的表头名称不可更改，表头行不能删除</h5>
            </div>
            <div>
              <el-button type="text">下载模板</el-button>
            </div>
          </el-card>
          <el-card style="margin-top:20px">
            <div>
              <h3><strong>上传填好的信息表</strong></h3>
              <h5>文件后缀名必须为xls或xlsx（即Excel格式），文件大小不得大于10M，最多支持导入3000条数据</h5>
            </div>
            <div>
              <el-upload
                ref="upload"
                class="upload-demo"
                :action="uploadUrl"
                :headers="headers"
                :on-success="handleSuccess"
                :before-upload="beforeUpload"
                :accept="accept"
              >
                <el-button size="middle" type="text">上传文件</el-button>
              </el-upload>
            </div>
          </el-card>
        </div>
        <div style="margin-top:20px;text-align: right">
          <el-button type="primary" @click="handleNext">下一步</el-button>
        </div>
      </el-dialog>
    </div> -->
    <!-- 固定资产导入异常信息 -->
    <!-- <div class="container">
      <el-dialog title="数据导入" :visible.sync="importErrorVisible">
        <div>
          <el-steps :active="1">
            <el-step title="上传文件"></el-step>
            <el-step title="数据预览"></el-step>
            <el-step title="导入数据"></el-step>
            <el-step title="导入完成"></el-step>
          </el-steps>
        </div>
        <div>
          <el-card style="margin-top:20px">
            <div>

              <h3><strong>正常数量条数: {{ importData.successNum }}</strong></h3>
              <h3><strong>异常数量条数: {{ importData.errorNum }}</strong></h3>
            </div>
          </el-card>
          <el-card style="margin-top:20px">
            <div>
              <h3><strong>异常提示：</strong></h3>
            </div>
            <div style="height: 200px; overflow-y: scroll;">
              <el-row v-for="item in importData.errorList" style="margin-bottom: 8px">
                <el-col :span="6"><strong>第{{ item.errLine }}行：</strong></el-col>
                <el-col :span="10">【{{ item.errCol }}】</el-col>
                <el-col :span="10">{{ item.errMsg }}</el-col>
              </el-row>
            </div>
          </el-card>
        </div>
        <div style="margin-top:20px;  text-align: right">
          <el-button type="primary" @click="previousStep">重新上传</el-button>
          <el-button type="primary" @click="showExcelData">下一步</el-button>
        </div>
      </el-dialog>
    </div> -->
    <!-- 导入数据预览 -->
    <!-- <div class="container">
      <el-dialog title="批量导入" :visible.sync="dataVisible">
        <div>
          <el-steps :active="2">
            <el-step title="上传文件"></el-step>
            <el-step title="数据预览"></el-step>
            <el-step title="导入数据"></el-step>
            <el-step title="导入完成"></el-step>
          </el-steps>
        </div>
        <div v-loading="excelImportLoading">
          <div>
            <el-table :data="excelList" max-height="450">
              <el-table-column label="固定资产标签编号" align="center" prop="assetTagNumber" width="180"></el-table-column>
              <el-table-column label="云中心资产标签" align="center" prop="cloudCenterAssetTag" width="180"></el-table-column>
              <el-table-column label="固定资产增加通知单固定资产编号" align="center" prop="noticeAssetNumber" width="180"
              ></el-table-column>
              <el-table-column label="固定资产增加通知单编号" align="center" prop="noticeNumber" width="180"></el-table-column>
              <el-table-column label="固定资产管理系统卡片号" align="center" prop="sysCardNumber" width="180"></el-table-column>
              <el-table-column label="固定资产管理系统卡片唯一编号" align="center" prop="sysCardUniqueNumber" width="180"
              ></el-table-column>
              <el-table-column label="固定资产管理系统目录代码" align="center" prop="sysDirectoryCode" width="180"
              ></el-table-column>
              <el-table-column label="资产分类" align="center" prop="assetClassify" width="180">
                <template slot-scope="{row}">{{ typeFormat(dict.type.fa_asset_classify, row.assetClassify) }}</template>
              </el-table-column>
              <el-table-column label="分类" align="center" prop="classify" width="180">
                <template slot-scope="{row}">{{ typeFormat(dict.type.fa_classify, row.assetClassify) }}</template>
              </el-table-column>
              <el-table-column label="设备名称" align="center" prop="deviceName" width="180"></el-table-column>
              <el-table-column label="品牌" align="center" prop="brand" width="180"></el-table-column>
              <el-table-column label="设备类型" align="center" prop="deviceType" width="180">
                <template slot-scope="{row}">{{ typeFormat(dict.type.fa_device_type, row.assetClassify) }}</template>
              </el-table-column>
              <el-table-column label="设备型号" align="center" prop="deviceType" width="180"></el-table-column>
              <el-table-column label="设备规格" align="center" prop="deviceSpec" width="180"></el-table-column>
              <el-table-column label="序列号" align="center" prop="serialNumber" width="180"></el-table-column>
              <el-table-column label="数量" align="center" prop="quantity" width="180"></el-table-column>
              <el-table-column label="单位" align="center" prop="unit" width="180"></el-table-column>
              <el-table-column label="金额" align="center" prop="amount" width="180"></el-table-column>
              <el-table-column label="重要程度" align="center" prop="importance" width="180"></el-table-column>
              <el-table-column label="固定资产明细账凭单号" align="center" prop="detailedAccountVoucherNumber" width="180"
              ></el-table-column>
              <el-table-column label="使用人" align="center" prop="peopleUse" width="180"></el-table-column>
              <el-table-column label="保管人" align="center" prop="preserver" width="180"></el-table-column>
              <el-table-column label="领用日期" align="center" prop="claimingDate" width="180"></el-table-column>
              <el-table-column label="办公场所" align="center" prop="officeSpace" width="180"></el-table-column>
              <el-table-column label="存放区域" align="center" prop="storageArea" width="180"></el-table-column>
              <el-table-column label="详细位置" align="center" prop="detailedLocation" width="180"></el-table-column>
              <el-table-column label="来源" align="center" prop="source" width="180"></el-table-column>
              <el-table-column label="组织采购形式" align="center" prop="organizationalPurchasingForm" width="180">
                <template slot-scope="{row}">
                  {{ typeFormat(dict.type.fa_organizational_purchasing_form, row.assetClassify) }}
                </template>
              </el-table-column>
              <el-table-column label="原领用人" align="center" prop="originalOwner" width="180"></el-table-column>
              <el-table-column label="盘实" align="center" prop="discRepletion" width="180"></el-table-column>
              <el-table-column label="标签" align="center" prop="tag" width="180"></el-table-column>
              <el-table-column label="设备状态" align="center" prop="status" width="180">
                <template slot-scope="{row}">{{ typeFormat(dict.type.fa_status, row.assetClassify) }}</template>
              </el-table-column>
              <el-table-column label="报废年限" align="center" prop="retirementLife" width="180"></el-table-column>
              <el-table-column label="处置方案" align="center" prop="disposalScheme" width="180">
                <template slot-scope="{row}">{{
                    typeFormat(dict.type.fa_disposal_scheme, row.assetClassify)
                  }}
                </template>
              </el-table-column>
              <el-table-column label="所属部门" align="center" prop="department" width="180"></el-table-column>
              <el-table-column label="处置优先级" align="center" prop="disposalPriority" width="180">
                <template slot-scope="{row}">{{
                    typeFormat(dict.type.fa_disposal_priority, row.assetClassify)
                  }}
                </template>
              </el-table-column>
              <el-table-column label="报废日期" align="center" prop="retirementDate" width="180"></el-table-column>
              <el-table-column label="报废状态" align="center" prop="retirementStatus" width="180">
                <template slot-scope="{row}">{{
                    typeFormat(dict.type.fa_retirement_status, row.assetClassify)
                  }}
                </template>
              </el-table-column>
              <el-table-column label="备注" align="center" sortable prop="note" width="180"></el-table-column>
            </el-table>
          </div>
          <div style="margin-top: 20px; text-align: right">
            <el-button type="primary" size="small" @click="previousStep">上一步</el-button>
            <el-button type="primary" size="small" @click="nextStep">导入数据</el-button>
          </div>
        </div>

      </el-dialog>
    </div> -->


  </div>
</template>

<script>
import Edit from './edit.vue'
import MoveAndInvalid from '@/views/finance/fixedAssets/components/MoveAndInvalid.vue'
import { getPage, exportAssets, importSaveData } from '@/api/bizFixAssets/bizFixAssetsApi.js'
import {
  budget_department,
  BudgetCategory
} from '@/api/financial/budgetExecution.js'
import { getEquForm } from '@/api/operations/equipment.js'
import { getToken } from '@/utils/auth'
import { deptListAll } from '@/api/administeration/askForLeave.js';
export default {
  name: 'assetsManage',
  components: { Edit, MoveAndInvalid },
  dicts: ['fa_device_type', 'fa_asset_classify', 'fa_classify', 'fa_organizational_purchasing_form', 'fa_status', 'fa_disposal_scheme', 'fa_disposal_priority', 'fa_retirement_status'],
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      open: false,
      // 查询条件显示条件
      showSearch: true,
      // 非多个禁用
      multiple: true,
      // 资产管理导入弹出层
      importVisible: false,
      importErrorVisible: false,
      dataVisible: false,
      uploadUrl: '/prod-api/system/bizFixedAssets/import', // 上传文件的后端接口地址
      headers: { 'Authorization': 'Bearer ' + getToken() },  // 令牌
      accept: '.xlsx,.xls', // 允许上传的文件类型
      excelImportLoading: false,
      excelList: [],
      importData: { // 导入excel结果
        errorNum: 0,
        successNum: 0,
        errorList: [],
        successList: []
      },

      detailVisible: false,
      excutionList: [],
      loading: false,
      claimingDateDateRange: [],
      retirementDateDateRange:[],
      queryParams: {
        status: '',
        assetTagNumber: '',
        sysCardNumber:'',
        deviceType: '',
        deviceName: '',
        
        discRepletion: '',
        department: '',
        disposalScheme: '',
        retirementLife: '',
        disposalPriority: '',
        tag: '',
        originalOwner: '',
        retirementStatus:'',
        pageNum: 0,
        pageSize: 10
      },
      deptOptions: [],
      sourcesList: [],
      departmentList: [],
      CategoryList: [],
      title: '',
      // 总条数
      total: 0
    }
  },
  computed: {
    edit() {
      return this.$refs.assetsEdit
    }
  },
  created() {
    this.getDeptListAll()
    this.inItPage()
    
  },
  mounted() {
    this.handleQuery()
  },
  methods: {
    // 排序
    changeTableSort({column,order}){
      console.log(column,order);
      if(column.property=='claimingDate'){
        this.queryParams.orderField='claimingDate'
        if(order=='ascending'){
            this.queryParams.orderType='asc'
          }else if(order=='descending') {
            this.queryParams.orderType='desc'
          }else {
            this.queryParams.orderType=null
          }
      }else if(column.property=='retirementDate'){
        this.queryParams.orderField='retirementDate'
        if(order=='ascending'){
            this.queryParams.orderType='asc'
          }else if(order=='descending') {
            this.queryParams.orderType='desc'
          }else {
            this.queryParams.orderType=null
          }
      }
      this.handleQuery()
    },
     // 下拉部门
    async getDeptListAll() {
      const deptres = await deptListAll()
      this.deptOptions = deptres.data
    },
    typeFormat(dict, column) {
      return this.selectDictLabel(dict, column)
    },
    // 详细按钮
    // handleIn(row) {

    // },
    // 部门查询
    inItPage() {
      budget_department().then(res => {
        for (let i = 0; i < res.data.length; i++) {
          this.departmentList.push(res.data[i].dictLabel)
        }
      })
    },
     // 文件状态改变时的钩子
       async upLoadExcel(file) {
            // 文件上传前做一下判断
            // const type_ALLOWD = ['doc', 'docx', 'txt', 'xls', 'xlsx', 'text', 'pdf']
            const type_ALLOWD = ['xls', 'xlsx']
            const fileType = file.raw.name.substring(
                file.raw.name.lastIndexOf('.') + 1
            )
            // 判断文件格式
            if (type_ALLOWD.indexOf(fileType) === -1) {
                this.$message({

                    message: "只能上传以'.xls'、 '.xlsx'结尾的文件,请重新上传！",
                    type: 'error',

                });
            } else {
                let formData = new FormData()
                formData.append('file', file.raw)

                const res = await importSaveData (formData)

                if (res) {
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                    } else {
                        this.$message.warning(res.msg)
                    }
                    this.handleQuery()
                } else {
                    this.$message.error('导入失败')
                }

            }
        },
        // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
        beforeUploadFile(file) {
            console.log('before upload');
            console.log(file);
            let extension = file.name.substring(file.name.lastIndexOf('.') + 1);
            let size = file.size / 1024 / 1024;
            if (extension !== 'xlsx') {
                this.$message.warning('只能上传后缀是.xlsx的文件');
            }
            if (size > 10) {
                this.$message.warning('文件大小不得超过10M');
            }
        },
    getDict() {
      BudgetCategory().then(res => {
        const { data } = res
        this.CategoryList = data
      })
    },
    handleDetail(row) {
      this.$router.push({
        path: '/workflow/process/assetsmanager/' + row.procInstId,
        query: {
          id: row.id,
          processed: false,
          category: row.category
        }
      })
    },

    // 报废申请
    async handlInvalid(row) {
      const res = await getEquForm({ processName: '报废申请' })
      this.$refs.MoveAndInvalid.show(
        row,
        res.data.form,
        res.data.process.definitionId,
        '报废申请')
    },
    // 申请预算调整
    async handleMove(row) {
      const res = await getEquForm({ processName: '调拨申请' })
      this.$refs.MoveAndInvalid.show(
        row,
        res.data.form,
        res.data.process.definitionId,
        '调拨申请')
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    handleImport() {
      this.importVisible = true
    },
    handleNext() {
      if (this.importData.errorNum > 0) {
        this.importErrorVisible = true
        this.importVisible = false
      } else {
        this.excelList = this.importData.successList
        this.importVisible = false
        this.dataVisible = true
      }
    },
    // 展示excel中的数据
    showExcelData() {
      this.excelList = this.importData.successList
      this.importVisible = false
      this.dataVisible = true
    },
    previousStep() {
      this.dataVisible = false
      this.importVisible = true
    },

    // 保存预览数据
    nextStep() {
      this.excelImportLoading = true
      importSaveData(this.excelList).then(resp => {
        if (resp && resp.code === 200) {
          this.$message.success('导入成功')

          this.importClose()
          this.resetQuery()
        }
      }).finally(() => {
        this.excelImportLoading = false
      })
    },
    importClose() {
      this.dataVisible = false
      this.importVisible = false
      this.importErrorVisible = false
      this.excelList = []
      this.importData = {}
      this.$refs.upload.clearFiles() // 清空upload组件文件列表
    },
    //上传成功的回调逻辑
    handleSuccess(response, file) {
      // 返回值校验
      if (!response || response.code !== 200) {
        this.$message.error('上传失败')
        return
      }
      if (!response.data || response.data.code !== 200) {
        this.$message.error('上传失败')
        return
      }
      if (response.data.data.length === 0) {
        this.$message.warning('解析为空Excel,请检查！')
        return
      }
      this.$message.success('文件上传成功')

      // 初始化预览表格
      this.importData = response.data.data

    },
    beforeUpload(file) {
      // 可以在此处新增上传文件前的验证逻辑
      const isFileTypeValid = this.accept.split(',').some(ext => file.name.endsWith(ext))
      if (!isFileTypeValid) {
        this.$message.error('文件类型不正确')
        return false // 阻止上传
      }
    },
    handleChange(val) {

    },

    /** 导出按钮操作 */
    handleExport() {
      console.log(this.ids)
      let list = []
      if (this.ids.length > 0) {
        this.ids.forEach(selectId => {
          let obj = this.excutionList.find(item => item.id === selectId)
          list.push(obj)
        })
        exportAssets(list).then(res => {
          if (res) {
            const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
            const fileName = '固定资产管理表.xlsx'
            if ('download' in document.createElement('a')) {
              // 非IE下载
              const elink = document.createElement('a')
              elink.download = fileName
              elink.style.display = 'none'
              elink.href = URL.createObjectURL(blob)
              document.body.appendChild(elink)
              elink.click()
              URL.revokeObjectURL(elink.href) // 释放URL 对象
              document.body.removeChild(elink)

            } else {
              // IE10+下载
              navigator.msSaveBlob(blob, fileName)
            }
            this.$refs.multipleTable.clearSelection()
          }

        })

      }
    },
    // 预算执行列表
    handleQuery() {
      this.loading = true
      if(this.claimingDateDateRange!=null&&this.claimingDateDateRange!=''){
        this.queryParams.claimingStartDate=this.claimingDateDateRange[0]
        this.queryParams.claimingEndDate=this.claimingDateDateRange[1]
      }else {
        this.queryParams.claimingStartDate=''
        this.queryParams.claimingEndDate=''
      }
      if(this.retirementDateDateRange!=null&&this.retirementDateDateRange!=''){
         this.queryParams.retirementStartDate=this.retirementDateDateRange[0]
        this.queryParams.retirementEndDate=this.retirementDateDateRange[1]
      }else {
        this.queryParams.retirementStartDate=''
        this.queryParams.retirementEndDate=''
      }
      getPage(this.queryParams).then(res => {
        this.excutionList = res.rows
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    },
    resetQuery() {
      this.claimingDateDateRange=[]
      this.retirementDateDateRange=[]
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        status: '',
        assetTagNumber: '',
        deviceType: '',
        deviceName: '',
        discRepletion: '',
        department: '',
        disposalScheme: '',
        retirementLife: '',
        disposalPriority: '',
        tag: '',
        originalOwner: '',
        sysCardNumber:'',
        orderField:'',
        retirementStatus:'',
      }
      this.handleQuery()
    },
    handleAdd() {
      this.edit.show()
    },
    handleEdit(row,falg) {
      this.$refs.assetsEdit.show(row,falg)
    }
  }
}

</script>

<style lang="scss" scoped>
.btn {
  margin-top: 10px;
}
</style>
